package com.youbug.mall.service_ucs.service.impl;

import com.youbug.common.to.OrderTo;
import com.youbug.mall.service_ucs.entity.UcsServiceTicket;
import com.youbug.mall.service_ucs.feign.IUcsWorkorderFeignService;
import com.youbug.mall.service_ucs.mapper.ServiceTicketMapper;
import com.youbug.mall.service_ucs.service.IServiceTicketService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 * 服务单表 服务实现类
 * </p>
 *
 * @author youbug
 * @since 2023-01-08
 */
@Service
public class ServiceTicketServiceImpl extends ServiceImpl<ServiceTicketMapper, UcsServiceTicket> implements IServiceTicketService {

    @Autowired
    private IUcsWorkorderFeignService ucsWorkorderFeignService;

    @Override
    @Transactional(transactionManager = "transactionManagerSystem", rollbackFor = Exception.class)
    public boolean saveTicketAndOrder(UcsServiceTicket ticket) {
        this.save(ticket);
        List<OrderTo> tos = ticket.getOrderTosTemp();
        
        return false;
    }

    @Override
    @Transactional(transactionManager = "transactionManagerSystem", rollbackFor = Exception.class)
    public boolean updateTicketAndOrder(UcsServiceTicket ticket) {
        this.updateById(ticket);
        List<OrderTo> tos = ticket.getOrderTosTemp();

        return false;
    }

    @Override
    public boolean createWorkorder(Long ticketId, List<OrderTo> tos) {

        ucsWorkorderFeignService.createWorkorder(ticketId, tos);
        UcsServiceTicket ticket = new UcsServiceTicket();
        ticket.setId(ticketId);
        ticket.setHasWorkorder("1");
        this.updateById(ticket);
        return true;
    }
}
